#coding:utf-8
from django.db import models
from datetime import datetime
import time
class Queue(models.Model):
    url = models.URLField(verbose_name=u'店铺地址')
    mail = models.CharField(max_length=100,verbose_name=u'用户邮箱')
    sales = models.IntegerField(blank=True,default=0,verbose_name=u'30天销量')
    money = models.IntegerField(blank=True,default=0,verbose_name=u'30销售额')
    stat = models.IntegerField(blank=True,default=0,verbose_name=u'任务状态')
    time = models.DateTimeField(verbose_name=u'添加时间',blank=True,default=datetime.fromtimestamp(int(time.time())))
    class Meta:
        db_table = 'queue'
        verbose_name =u'任务队列'
        verbose_name_plural =u'任务队列'
        #app_label = u'我的应用'
    def __unicode__(self):
        return str(self.id)

class User(models.Model):
    username = models.CharField(max_length=255,verbose_name=u'用户名')
    password = models.CharField(max_length=32,verbose_name=u'密码')

    def __unicode__(self):
        return self.username
    class Meta:
        db_table = 'user'
        verbose_name =u'用户'
        verbose_name_plural =u'用户'
        #app_label = u'我的应用'
class Store(models.Model):
    store_name = models.CharField(max_length=255,verbose_name=u'店铺名称')
    store_url = models.CharField(max_length=255,verbose_name=u'店铺地址')
    def __unicode__(self):
        return self.store_name
    class Meta:
        db_table = 'store'
        verbose_name =u'店铺基本信息'
        verbose_name_plural =u'店铺基本信息'
        #app_label = u'我的应用'

class Task(models.Model):
    task_name = models.CharField(max_length=255,verbose_name=u'任务名称')
    user = models.ForeignKey(User,verbose_name=u'订阅用户',blank=True,null=True)
    store = models.ForeignKey(Store,verbose_name=u'订阅店铺',blank=True,null=True)
    stat = models.SmallIntegerField(max_length=1,default=1,verbose_name=u'任务状态')
    last_time = models.IntegerField(max_length=10,verbose_name=u'上次执行时间',default=0)
    def del_task(self):
        pass
    def add_task(self):
        pass
    def __unicode__(self):
        return self.task_name
    class Meta:
        db_table = 'task'
        verbose_name =u'用户订阅'
        verbose_name_plural =u'用户订阅'
        #app_label = u'我的应用'


class Store_info(models.Model):
    task = models.ForeignKey(Task)
    store = models.ForeignKey(Store)
    sale_count = models.IntegerField(blank=True,default=0,verbose_name=u'30天销量')
    sale_money =models.DecimalField(blank=True,default=0,max_digits=12,decimal_places=1,verbose_name=u'30天销售额')
    date = models.DateField(verbose_name=u'采集日期')
    def __unicode__(self):
        return self.date
    class Meta:
        db_table = 'store_info'
        verbose_name =u'店铺销量信息'
        verbose_name_plural =u'店铺销量信息'
        #app_label = u'我的应用'